package com.atguigu.gulimall.search.controller;


import com.atguigu.common.exception.BizCodeEnume;
import com.atguigu.common.to.es.SkuEsModel;
import com.atguigu.common.utils.R;
import com.atguigu.gulimall.search.service.ProductSaveService;
import lombok.extern.slf4j.Slf4j;
import org.apache.http.conn.routing.HttpRouteDirector;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.List;

@RestController
@RequestMapping("/search/save")

@Slf4j
public class ElasticSaveController {




    @Autowired
    private ProductSaveService productSaveService;

    @PostMapping("/product")
    public R productStatusUP(@RequestBody List<SkuEsModel> skuEsModels)  {   //   上架!!


        boolean b=false;
        try {
            b=productSaveService.productStatusUP(skuEsModels);
        } catch (IOException e) {
//            throw new RuntimeException(e);

            log.error("ElasticSaveController商品上架错误:{}",e);
            return  R.error(BizCodeEnume.PRODUCT_UP_EXCEPTION.getCode(), BizCodeEnume.PRODUCT_UP_EXCEPTION.getMsg());



        }
        if(b==false){
        return R.ok();

        }else{
            return  R.error(BizCodeEnume.PRODUCT_UP_EXCEPTION.getCode(), BizCodeEnume.PRODUCT_UP_EXCEPTION.getMsg());
        }


    }


}
